import Vue from 'vue'
import VueRouter from 'vue-router'
// 登录页面
import Login from '../views/Login'
// 首页
import Layout from '../views/Layout'
import Home from '../views/Layout/Home'
const ArticleDetail = () => import(/* webpackChunkName:ArticleDetail */ '../views/Article/id.vue')
const UserEdit = () => import(/* webpackChunkName:UserEdit */ '../views/UserEdit/index.vue')
const Chat = () => import(/* webpackChunkName:Chat */ '../views/Chat')
const SearchResultList = () => import(/* webpackChunkName:SearchResultList */ '../views/Search/ResultList.vue')
const User = () => import(/* webpackChunkName:User */ '../views/Layout/User')
// 路由懒加载，写成函数的格式 webpack 打包的时候
// 看到这个标识就不会不加载这个文件
// webpackChunkName 用来指明打包后生成的文件名
const Search = () => import(/* webpackChunkName:Search */ '@/views/Search')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login' // 重定向
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home', // 默认显示二级页面为home首页
    children: [
      {
        path: 'home',
        component: Home,
        meta: { // 给路由对象添加额外的信息
          scrollY: 0
        }
      },
      {
        path: 'user',
        component: User
      }
    ]
  },
  { // 搜索页
    path: '/search',
    component: Search
  },
  { // 搜索结果页
    path: '/search/:keyword', // 动态路由
    component: SearchResultList
  },
  { // 详情页
    path: '/article',
    component: ArticleDetail
  },
  {
    path: '/user/edit',
    component: UserEdit
  },
  {
    path: '/chat',
    component: Chat
  }
]

const router = new VueRouter({
  routes
})

export default router
